package com.hhl;

public class ThreadDemo5 {
	// 1.现在有T1、T2、T3三个线程，你怎样保证T2在T1执行完后执行，T3在T2执行完后执行  

	public static void main(String[] args) {
		Thread t1 = new Thread(new Runnable() {
			@Override
			public void run() {
				for (int i = 0; i < 10; i++) {
					try {
						Thread.sleep(300);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("t1线程" + i);
				}

			}
		});
		Thread t2 = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					t1.join();
				} catch (InterruptedException e1) {
					e1.printStackTrace();
				}
				for (int i = 0; i < 10; i++) {
					try {
						Thread.sleep(400);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("t2线程" + i);
				}

			}
		});

		Thread t3 = new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					t2.join();
				} catch (InterruptedException e1) {
					e1.printStackTrace();
				}
				for (int i = 0; i < 10; i++) {
					try {
						Thread.sleep(230);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("t3线程" + i);
				}

			}
		});
		
		try {
			t1.start();
//			t1.join();
			t2.start();
//			t2.join();
			t3.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
